package koala.kuangjiademo.data;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.wwgps.ect.BuildConfig;

import java.io.Serializable;
import java.util.List;

public class AppVersion implements Serializable {
    @SerializedName("packagename")
    public String packageName;
    @SerializedName("versioncode")
    public int versionCode;

    public boolean haseNew() {
        return !TextUtils.isEmpty(versionName) && !BuildConfig.VERSION_NAME.equals(versionName);
    }

    @SerializedName("versiontype")
    public int type;
    @SerializedName("versionname")
    private String versionName;
    @SerializedName("forceupdate")
    private int forceUpdate;

    public boolean isForceUpdate() {
        return forceUpdate == 1;
    }

    public String getUrl() {
        return url;
    }

    @NonNull
    public String getVersionName() {
        if (versionName != null) {
            return versionName;
        } else return "";
    }

    @NonNull
    public String getUpdateInfo() {
        return TextUtils.isEmpty(message) ? "" : message;
    }

    public float getFileSize() {
        return size;
    }

    private String url;
    /**
     * 软件大小，单位 byte
     */
    @SerializedName("packagesize")
    public int size;
    private String message;
    @SerializedName("errorcode")
    private int error_code;

    public boolean isSuccess() {
        return error_code == 0;
    }

    public static class Data implements Serializable {
        private List<AppVersion> records;

        public AppVersion getAppVersion() {
            if (records.isEmpty()) return new AppVersion();
            else return records.get(0);
        }
    }

    public static class Response extends ResponsePacket<Data> {

    }
}
